import React, { Component, PureComponent, memo } from 'react'
export class Test extends PureComponent {
  constructor(props) {
    super(props)
    this.state = {
      firends: [
        { name: 'bob', age: 18 },
        { name: 'kob', age: 10 },
      ],
    }
  }
  firendIsOld(item) {
    // 1.在Component下方法正常，在PureComponent下失效了
    // item.age += 1
    // this.setState({})

    // 2.在Component下方法正常，在PureComponent下方法正常
    item.age += 1
    const newFirends = [...this.state.firends]
    this.setState({ firends: newFirends })
  }
  render() {
    return (
      <>
        {this.state.firends.map(item => {
          return (
            <div key={item.name}>
              姓名: {item.name} 年龄 {item.age}
              <button onClick={() => this.firendIsOld(item)}>年龄加1</button>
            </div>
          )
        })}
      </>
    )
  }
}
